<script type="text/javascript">
  var str = 'aaa bbb ccc';
  document.write(str.replace(/\b\w+\b/g, function (word) {
    return word.substring(0, 1).toUpperCase() + word.substring(1);
  }));
</script>